package org.jugile.demo.domain;

import org.jugile.daims.Bo;
import org.jugile.daims.anno.*;
import org.jugile.util.Time;
import org.jugile.util.Money;
import org.jugile.demo.common.*;


@DaimsObject(table="library_t")
public class LibraryBase extends Bo {

	public String getName(String lang) {
		if ("fi".equals(lang)) return getName_fi();
		if ("sv".equals(lang)) return getName_sv();
		return null;
	}	
	public String getName() { return getName(d().getLang()); }
 
	@Fld // field
	private int num;
	public int getNum() { return num; }
	public Library setNum(int v) { return (Library)setFld("num",v); }
 
	public String getDesc(String lang) {
		if ("fi".equals(lang)) return getDesc_fi();
		if ("sv".equals(lang)) return getDesc_sv();
		return null;
	}	
	public String getDesc() { return getDesc(d().getLang()); }
 
	@Fld(size=330) // field
	private String name_fi;
	public String getName_fi() { return name_fi; }
	public Library setName_fi(String v) { return (Library)setFld("name_fi",v); }
 
	@Fld(size=330) // field
	private String name_sv;
	public String getName_sv() { return name_sv; }
	public Library setName_sv(String v) { return (Library)setFld("name_sv",v); }
 
	@Fld(size=10000) // field
	private String desc_fi;
	public String getDesc_fi() { return desc_fi; }
	public Library setDesc_fi(String v) { return (Library)setFld("desc_fi",v); }
 
	@Fld(size=10000) // field
	private String desc_sv;
	public String getDesc_sv() { return desc_sv; }
	public Library setDesc_sv(String v) { return (Library)setFld("desc_sv",v); }
 
 
 
	// --- n - 1 ----
 
	// --- 1 - n ----
	@Connection1N(o="library")
	private VisitCollection cVisits = new VisitCollection();
	public VisitCollection getVisits() { return (VisitCollection)getAll("cVisits"); }
	public Library addVisit(Visit o) { add("cVisits",o); return (Library)this; }
	public void removeVisit(Visit o) { remove("cVisits",o); } 

 
	// --- n - n ---
 	@ConnectionNN(c="mLibraries")
	private BookCollection mBooks = new BookCollection();
	public BookCollection getBooks() { return (BookCollection)getAll("mBooks"); }
	public Library addBook(Book o) { add("mBooks",o); return (Library)this; }
	public void removeBook(Book o) { remove("mBooks",o); }
	
	public void toggle(Book v) {
		if (getBooks().contains(v)) removeBook(v);
		else addBook(v);		
	}
	public boolean has(Book v) { return getBooks().contains(v); }
	
 	@ConnectionNN(c="mSideLibraries")
	private BookCollection mSideBooks = new BookCollection();
	public BookCollection getSideBooks() { return (BookCollection)getAll("mSideBooks"); }
	public Library addSideBook(Book o) { add("mSideBooks",o); return (Library)this; }
	public void removeSideBook(Book o) { remove("mSideBooks",o); }
	
	public void toggleSide(Book v) {
		if (getSideBooks().contains(v)) removeBook(v);
		else addBook(v);		
	}
	public boolean hasSide(Book v) { return getSideBooks().contains(v); }
	
 

	// ---- common utils ----
	protected Domain d() { return Domain.getDomain(); }


}